<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PortalUpgrade.php 387 2010-12-22 14:06:40Z steen.rabol $
 *
 */


class PortalUpgrade extends TComponent
{
	private	$_app			= null;
	private $_db			= null;
	private	$_configid		= null;
	private	$_fromversion	= '1.0.0';

	public function __construct($p_app,$p_configid,$p_fromversion)
	{
		$this->_app			= $p_app;
		$this->_db			= $this->_app->DbConnection;

		$this->_configid	= $p_configid;
		$this->_fromversion	= $p_fromversion;
	}

	public function getDbConnection()
	{
		return $this->_db;
	}

	public function run()
	{
	}

	public function getApplication()
	{
		return $this->_app;
	}
	public function UpdVersionNum($p_newversion)
	{
		// As last step set new version information
		if($this->_configid === null)
		{
			$sql = "insert into tblconfig(name,value) values('portalversion','$p_newversion')";
		}
		else
		{
			$sql = "update tblconfig set value='$p_newversion' where id=" . $this->_configid;
		}

		$this->DbConnection->createCommand($sql)->execute();
	}

	public function Upgrade()
	{
		switch($this->_fromversion)
		{
			case "1.0":
				$this->upg_1_0_To_1_0_1();
				// fall through to upgrade next
			case "1.0.1":
				$this->upg_1_0_1_To_1_0_2();
				// fall through to upgrade next
			case "1.0.2":
				$this->upg_1_0_2_To_1_0_3();
				// fall through to upgrade next
			case "1.0.3":
				$this->upg_1_0_3_To_1_0_4();
				// fall through to upgrade next
			case "1.0.4":
				$this->upg_1_0_4_To_1_0_5();
				// fall through to upgrade next
			case "1.0.5":
				$this->upg_1_0_5_To_1_1_0();
				// fall through to upgrade next
			case "1.1.0":
				$this->upg_1_1_0_To_1_2_0();
				// fall through to upgrade next
            case "1.2.0":
                $this->upg_1_2_0_To_1_2_1();
                // fall through to upgrade next

		}

	}

	private function upg_1_0_To_1_0_1()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_To_1_0_1.Upgrade');
		//PortalUtil::Log("Upgrade from 1.0 to 1.0.1");
		$upd = new Upgrade($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.0.1';
	}

	private function upg_1_0_1_To_1_0_2()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_1_To_1_0_2.Upgrade_1_0_1');
		//PortalUtil::Log("Upgrade from 1.0.1 to 1.0.2");
		$upd = new Upgrade_1_0_1($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.0.2';
	}

	private function upg_1_0_2_To_1_0_3()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_2_To_1_0_3.Upgrade_1_0_2');
		//PortalUtil::Log("Upgrade from 1.0.2 to 1.0.3");
		$upd = new Upgrade_1_0_2($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.0.3';
	}

	private function upg_1_0_3_To_1_0_4()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_3_To_1_0_4.Upgrade_1_0_3');
		//PortalUtil::Log("Upgrade from 1.0.3 to 1.0.4");
		$upd = new Upgrade_1_0_3($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.0.4';
	}

	private function upg_1_0_4_To_1_0_5()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_4_To_1_0_5.Upgrade_1_0_4');
		//PortalUtil::Log("Upgrade from 1.0.4 to 1.0.5");
		$upd = new Upgrade_1_0_4($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.0.5';
	}

	private function upg_1_0_5_To_1_1_0()
	{
		Prado::using('Application.Common.Upgrade.upg_1_0_5_To_1_1_0.Upgrade_1_0_5');
		//PortalUtil::Log("Upgrade from 1.0.5 to 1.1.0");
		$upd = new Upgrade_1_0_5($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.1.0';

		/*
		ALTER TABLE `tblsimpletext` CHANGE `css` `css` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
		*/
	}

	private function upg_1_1_0_To_1_2_0()
	{
		Prado::using('Application.Common.Upgrade.upg_1_1_0_To_1_2_0.Upgrade_1_1_0');
		//PortalUtil::Log("Upgrade from 1.1.0 to 1.2.0");
		$upd = new Upgrade_1_1_0($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.2.0';

		/*
		ALTER TABLE `tblsimpletext` CHANGE `css` `css` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
		*/
	}
	private function upg_1_2_0_To_1_2_1()
	{
		Prado::using('Application.Common.Upgrade.upg_1_2_0_To_1_2_1.Upgrade');
		PortalUtil::Info("Upgrade from 1.2.0 to 1.2.1");
		$upd = new Upgrade_1_2_0($this->_app,$this->_configid,$this->_fromversion);
		$upd->run();
		$this->_fromversion	= '1.2.1';

	}

}
?>